<template>
  <div :fieldrender="field.field">
    <div v-show="isShow"> <img field="field.field" handsign-field="field.field" :src="src" :width="width" /></div>
    <el-button :field="field.field" size="mini" v-if="!isReadOnly" type="primary" title="选择" @click="openDialogClick"><i class="fa fa-search">选择图章</i></el-button>
  </div>
</template>

<script>
  export default {
    name: 'f2bpmuiStamp',
    props: ['field', 'fieldvalue','readOnly'],
    data: function () {
      return {
        isView: false,
        isReadOnly: false,
        isShow: false,
        value: '',
        src: '',
        inputCtrlOption: null,
        prefix: '',
        width: ''
      }
    },
    watch: {
      value(val, oleV) {
        var that = this;
        if (val != undefined && oleV != undefined ) {
          this.$emit('updatevalue', that.field.fieldName, val);
        }
      }
    },
    created: function () {
      var that = this;
      that.initailFieldOption();
      that.value = that.fieldvalue;
      if (that.readOnly != undefined&&that.readOnly!=null) {
        that.isReadOnly = that.readOnly;
        that.isView= that.readOnly;
      }
      var prefix = '';
      if (that.field.inputCtrlOption) {
        var json = typeof that.field.inputCtrlOption === 'object' ? that.field.inputCtrlOption : eval('(' + that.field.inputCtrlOption + ')');
        that.inputCtrlOption = json;
        prefix = that.inputCtrlOption.showPathPrefix;
      }
      var width = that.field.width || 120;
      if (width == 0) {
        width = 120;
      }
      that.width = width + 'px';
      that.prefix = prefix;
      that.showSrc();
      if (that.value) {
        this.isShow = true;
      }
    },
    mounted() {
      var that = this;
    },
    methods: {
      initailFieldOption() {
        var that = this
        if (that.field.fieldOptions) {
          var fieldOptions = typeof that.field.fieldOptions === 'string' ? eval('(' + that.field.fieldOptions + ')') : that.field.fieldOptions;
          var general = fieldOptions.find(a => a.opttype == 'general')
          if (general) {
            var kvData = general.params.kvData;
          }
        }
      },
      openDialogClick() {
        var that = this
        var currUserId = FUI.Sys.getAuthor().userId;
        var url = __webpath + '/workflow/selector/selectPersonalSeal/?sealType=&currUserId=' + currUserId;
        FUI.dialog(url, '选择图章', {}, 800, 450, function (data, index, layer) {
          if (data && data.length > 0) {
            that.value = data[0].sealPhoto;
            that.showSrc();
            that.isShow = true;
          }
          layer.close(index);
          return false;
        }, false, null, { sure: { text: '确定' } });
      },
      showSrc() {
        var that = this;
        var src = '';
        var pathType = 'seal';
        if (that.value) {
          // 数组
          var item = eval('(' + that.value + ')');
          item = item[0]
          src = __serverpath + FUI.Handlers.Common + 'getShowImage/?pathType=' + pathType + '&groupName=' + item.groupName + '&filePath=' + item.filePathName;
        }
        that.src = src;
      }
    }
  }
</script>